<?php


namespace app\admin\controller;


use think\App;

/**
 * Created by PhpStorm
 * USER zhangkai QQ 920062039
 * Date 2022/6/16   16:20
 * @property \app\admin\logic\CodeGeneration logicCodeGeneration
 */
class CodeGeneration extends ControllerBase
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        // 本服务只有在 local环境下才可使用
        if(app()->env->get('APP_ENV') != 'local'){
            exception('无访问权限');
        }
    }

    /**
     * @OA\Get(
     *   tags={"代码生成"},
     *   path="/codeGeneration/getTableList",
     *   summary="获取数据库表列表",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description="返回项目数据库表"
     *   )
     * )
     */
    public function getTableList(){
        return result()->data($this->logicCodeGeneration->getTableList())->toJson();
    }

    /**
     * @OA\POST (
     *   tags={"代码生成"},
     *   path="/codeGeneration/getTableColumns",
     *   summary="获取数据库表字段详情",
     *   @OA\RequestBody(
     *         @OA\MediaType(
     *             mediaType="application/json",
     *             @OA\Schema(
     *                 @OA\Property(
     *                     description="数据库表名",
     *                     property="table",
     *                     type="string"
     *                 ),
     *                 example={"table": "user"},
     *                 required={"table"}
     *             )
     *         )
     *   ),
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description="返回项目数据库表"
     *   )
     * )
     */
    public function getTableColumns(){
        return result()->data($this->logicCodeGeneration->getTableColumns(request()->param()))->toJson();
    }

    /**
     * @OA\POST (
     *   tags={"代码生成"},
     *   path="/codeGeneration/generateCode",
     *   @OA\Parameter(name="param", in="query", @OA\Schema(type="string"), required=true, description="生成的json"),
     *   summary="生成代码",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description="返回项目数据库表"
     *   )
     * )
     */
    public function generateCode(){
        return result()->data($this->logicCodeGeneration->generateCode(request()->param()))->toJson();
    }

    /**
     * @OA\POST (
     *   tags={"代码生成"},
     *   path="/codeGeneration/getAllModules",
     *   summary="获取所有模块",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description="返回项目数据库表"
     *   )
     * )
     */
    public function getAllModules(){
        return result()->data($this->logicCodeGeneration->getAllModules())->toJson();
    }
}